package com.guli.edu.controller.admin;

import com.guli.common.vo.R;
import com.guli.edu.form.VideoInfoForm;
import com.guli.edu.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author XiaoHua666
 * @date 2019/4/26
 */
@Api(tags = "课时管理")
@RestController
@CrossOrigin
@RequestMapping("admin/edu/video")
public class VideoAdminController {
    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "新增课时")
    @PostMapping("save-video-info")
    public R save(
            @ApiParam(value = "课时对象", name = "videoForm", required = true)
            @RequestBody VideoInfoForm videoInfoForm
    ) {
        videoService.saveVideoInfo(videoInfoForm);
        return R.ok();
    }

    @ApiOperation(value = "修改课时")
    @PutMapping("update-video-info/{id}")
    public R updateById(
            @ApiParam(value = "课时基本信息", name = "videoForm", required = true)
            @RequestBody VideoInfoForm videoInfoForm,
            @ApiParam(value = "课时id" , name = "id", required = true)
            @PathVariable("id") String id
    ) {
        videoInfoForm.setId(id);
        videoService.updateVideoInfoById(videoInfoForm);

        return R.ok();
    }
    @ApiOperation(value = "获取课时")
    @GetMapping("video-info/{id}")
    public R getVideoInfoById(
            @ApiParam(value = "课时id" , name = "id", required = true)
            @PathVariable("id") String id
    ) {
       VideoInfoForm videoInfoForm =  videoService.getVideoInfoFormById(id);

        return R.ok().data("item", videoInfoForm);
    }

    @ApiOperation(value = "删除课时")
    @DeleteMapping("{id}")

    public R removeVideoInfoById(
            @ApiParam(value = "课时id" , name = "id", required = true)
            @PathVariable("id") String id
    ) {
       videoService.removeVideoInfoById(id);

        return R.ok();
    }


}
